{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e5082c9c",
   "metadata": {},
   "source": [
    "# 本周内容：Web应用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4fce375",
   "metadata": {},
   "source": [
    "## 1.使用Flask搭建Web最小应用  \n",
    "> 1.使用select创建一个html页面：index.html  \n",
    "> 2.使用Flsak中的 render_template 实现页面的路由跳转"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97da0486",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app '__main__'\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\n",
      " * Running on http://127.0.0.1:5000\n",
      "Press CTRL+C to quit\n",
      "127.0.0.1 - - [22/Nov/2023 19:18:15] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [22/Nov/2023 19:18:15] \"GET /favicon.ico HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [22/Nov/2023 19:18:15] \"GET /assets/drop-wrapper-pic-GDO35LIT.png HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [22/Nov/2023 19:18:20] \"POST /user_choose HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [22/Nov/2023 19:18:20] \"GET /assets/drop-wrapper-pic-GDO35LIT.png HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [22/Nov/2023 20:26:31] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [22/Nov/2023 20:26:40] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [22/Nov/2023 20:26:49] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [22/Nov/2023 20:29:17] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [22/Nov/2023 20:29:34] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [22/Nov/2023 20:29:36] \"GET / HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def hello_world():\n",
    "    return render_template('index.html')\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1eb7236",
   "metadata": {},
   "source": [
    "## 2. 提交表单的内容在python中接收"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b950c0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template,request\n",
    "import crawl_liepin\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template(\"index.html\")\n",
    "\n",
    "@app.route('/user_choose',methods = ['POST', 'GET'])\n",
    "def user_choose():\n",
    "    print(request.form['city'])\n",
    "    print(request.form['category'])\n",
    "    print(request.form['workexp'])\n",
    "    user_city = request.form['city']\n",
    "    user_category = request.form['category']\n",
    "    user_workexp = request.form['workexp']\n",
    "    crawl_results = crawl_liepin.crawl(城市 = user_city ,关键词=user_category,工作经验=user_workexp)\n",
    "    crawl_results_html = crawl_results.to_html[\n",
    "        [\n",
    "            'recruiter.recruiterTitle',\n",
    "            'comp.conpScale',\n",
    "            'comp.conpStage',\n",
    "            'comp,conpIndustry',\n",
    "            'comp.conpName',\n",
    "            'job.labels',\n",
    "            'job.dp',\n",
    "            'job.c',\n",
    "            'job.title',\n",
    "            'job.salary'\n",
    "        ]\n",
    "    ]\n",
    "    crawl_results_df.to.excel()\n",
    "    crawl_results_html = crawl_results.to_html()\n",
    "    return render_template(\"user_choose.html\",\n",
    "                           crawl_results_html=crawl_results_html)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e07f2cb5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
